<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<style type="text/css">
		.advance_tip_pwd{
			background-color: #fff;
		    left: 42%;
		    position: fixed;
		    top: 200px;
		    width: 487px;
		    z-index: 5;
		}
		
		</style>
	</head>
	
	<body>
		<div class="cinema_tip">
		    <div class="cinema_subject clearfix">
		        <div class="cinema_title">
		            <a href="#">用户中心</a>
		            >
		            <a href="#" class="cinema_option">用户管理</a>
		        </div>
		    </div>
			<form  id="sysUserInfoSearchForm" method="post">
		       <div class="cinema_search clearfix">
					<div class="cinema_button">
				        	<input id="sysUserInfoSearch" type="submit" value="查询" style="float: none;" class="cinema_inquiry movie_no" >
					</div>
					<div class="cinema_condition width_84">
						<div class="cinema_smart" style="float:none">
							<div class="cinema_inter" style="margin-bottom: 10px">
								<!-- <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 用户名： </label> -->
								<input type="text" id="search_userName" name="search_userName" maxlength="50" placeholder="登录账号或用户名" class="col-xs-10 col-sm-2" value="${searchUserName}"/>
							</div>
							
							<c:if test="${sessionScope.loginUser.roleId eq 1 || sessionScope.loginUser.roleId eq 7 ||sessionScope.loginUser.roleId eq 9}">
							<dt >
							<div class="cinema_inter">
								<label class="col-sm-1 control-label no-padding-right" for="form-field-1" style="float:left;line-height:33px;padding-left:10px;"> 项目名称： </label>
								<div style="float:left;margin-top: -15px;">
								<select name="projectId" id="projectId">
									<option value="0">请选择项目名称</option>
										<c:forEach var="project" items="${projectRes.data}">
											<option value="${project.proId}" <c:if test="${project.proId eq projectId}">selected</c:if>>${project.name}</option>
										</c:forEach>
								</select>
								</div>
							</div>
							</dt>
							</c:if>
						</div>
					</div>
				</div>
			</form>
		</div>
		
		
		<div class="cinema_list">
		    <div class="movie_button">
		    	<shiro:hasPermission name="sysUserInfo:add">
					<a class="movie_new" href="#" style="background-color: rgb(75, 208, 131); color: rgb(255, 255, 255);">新建</a>
				</shiro:hasPermission>
		    <div  class="column_content">
			    <div class="column_content1" style="overflow: auto;">
			        <table id="sysUserInfoDatas" width="100%" height="" border="0" cellpadding="0" cellspacing="1" class="border_top">
			            <tr style="background-color: rgb(243, 247, 255);">
			                <th nowrap="" style="padding:0px 5px;width:200px">账号</th>
			                <th nowrap="" style="padding:0px 5px;width:200px">姓名</th>
			                <th nowrap="" style="padding:0px 5px;width:200px">角色</th>
			                <th nowrap="" style="padding:0px 5px;">项目</th>
			                <th nowrap="" style="padding:0px 5px;">工段</th>
			                <th nowrap="" style="padding:0px 5px;">审批状态</th>
			                <th nowrap="" style="padding:0px 5px;">是否禁用</th>
			                <th nowrap="" style="padding:0px 5px;width:200px">操作</th>
			            </tr>
			            <c:forEach var="res" items="${res.data.rows}">
				            <tr class="odd" style="background-color: rgb(255, 255, 255);" id="userinfo_row_${res.user_id}" >
				                 <td nowrap="" style="padding:0px 5px;width:200px" title="${res.loginName}">&nbsp;${res.loginName}</td>
				                 <td nowrap="" style="padding:0px 5px;width:200px" title="${res.userName}">&nbsp;${res.userName}</td>
				                 <td nowrap="" style="padding:0px 5px;width:200px" title="${res.role.roleName}">&nbsp;${res.role.roleName}</td>
				                 <td nowrap="" style="padding:0px 5px;" title="${res.projectID}">&nbsp;${res.projectName}</td>
				                 <td nowrap="" style="padding:0px 5px;" title="${res.segmentID}">&nbsp;${res.segmentName}</td>
				                 <td nowrap="" style="padding:0px 5px;" title="${res.status}">&nbsp;
				                 <c:choose>
				                 	<c:when test="${res.status==1}">未审批</c:when>
				                 	<c:when test="${res.status==2}">已审批</c:when>
				                 </c:choose>
				                 </td>
				                 <td nowrap="" style="padding:0px 5px;" title="${res.isAvailable}" id="userinfo_row_stats_${res.user_id}">&nbsp;
				                 <c:choose>
				                 	<c:when test="${res.isAvailable==0}">是</c:when>
				                 	<c:when test="${res.isAvailable==1}">否</c:when>
				                 </c:choose>
				                 </td>
				                 <td nowrap="" style="padding:0px 5px;width:150px" >
				                 	<a style="margin-left: 3%;" href="${ctx}/sys/user/toUpdate/${res.user_id}" title="${ctx}/sys/user/update/${res.user_id}">编辑</a>
				                 	<a style="margin-left: 3%;" href="${ctx}/sys/user/approve?userId=${res.user_id}">审批</a>
				                 	<a style="margin-left: 3%;" href="javascript:resetPwd(${res.user_id});">重置密码</a>
				                 	<c:choose>
				                 		<c:when test="${res.isAvailable==1}">
				                 			<a style="margin-left: 3%;" href="javascript:disableUser(${res.user_id},0);">禁用</a>
				                 		</c:when>
				                 		<c:when test="${res.isAvailable==0}">
				                 			<a style="margin-left: 3%;" href="javascript:disableUser(${res.user_id},1);">启用</a>
				                 		</c:when>
				                 	</c:choose>
				                 	
								</td>
				             </tr>
			            </c:forEach>
					</table>
				</div>
			</div><!-- /.row -->
			<div id="manager_page" class="manager_page clearfix">
				<!-- 分页跳转 -->
				<div class="manager_show">
					<p><span>跳转至</span><input id="pagenum" type="text" name="" value="${res.data.page}"/></p>
					<span id="toPage" class="manager_true"></span>
				</div>
				<!-- 分页数字导航栏 -->
				<div id="manager_number" class="manager_number"></div>
				<input type="hidden"  id=records  value="${res.data.records}"/>			<!-- 总记录数 -->
				<input type="hidden"  id="pageSize"  value="${res.data.pageSize}"/>  <!-- 每页个数 -->
				<input type="hidden"  id="pageCurrent"  value="${res.data.page}"/>  <!-- 当前页page -->
				<input type="hidden"  id="totalPage"  value="${res.data.total}"/>	    <!-- 总页数 -->
			</div>
		</div>
		<script type="text/javascript">
	function resetPwd(userId){
		if(confirm("您确认重置该用户密码吗?")){
			resetRowById(userId);
		}
	}
	
	//删除工段ajax请求
	function resetRowById(rowId){
		$.ajax({
			type: "POST",
			dataType: "json",
			async: false,
			url: '${ctx}/sys/user/resetPwd/'+rowId,
			success: function (data) {
						if(data!=undefined&&data.status!=undefined&&data.status.trim()=="0"){
							//$("#userinfo_row_"+rowId).remove();
							alert("重置成功。");
						}else{
							alert("error:"+data.error);
						}
					 },
			error: function(data) {
						alert("重置失败。");
					}
		});
		return false;
	}
	
	function disableUser(userId,state){
		$.ajax({
			type: "POST",
			dataType: "json",
			async: false,
			url: '${ctx}/sys/user/disableUser/'+userId+'/'+state,
			success: function (data) {
						if(data!=undefined&&data.status!=undefined&&data.status.trim()=="0"){
							//$("#userinfo_row_"+rowId).remove();
							alert("修改成功。");
							self.location.href = '${ctx}/sys/user/listUser';
						}else{
							alert("error:"+data.error);
						}
					 },
			error: function(data) {
						alert("修改失败。");
					}
		});
		return false;
	}
	</script>
	</body>
	
</html>
